package cn.liulin.spring_boot_study;

import cn.liulin.spring_boot_study.config.*;
import cn.liulin.spring_boot_study.pojo.Person;
import cn.liulin.spring_boot_study.scope.BeanScope;
import com.alibaba.fastjson.JSON;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;

/**
 * cn.liulin.spring_boot_study$
 *
 * @author ll
 * @date 2021-10-22 13:52:22
 **/
public class MainRun {
    public static void main(String[] args) {
//        mainOne();
//        mainTwo();
//        mainThree();
//        mainFour();
//        mainFive();
        mainSix();
    }

    private static void mainSix() {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BeanScopeConfig.class);
        BeanScope beanScope1 = applicationContext.getBean(BeanScope.class);
        BeanScope beanScope2 = applicationContext.getBean(BeanScope.class);
        System.out.println(beanScope1 == beanScope2);
    }


    private static void mainFive() {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConditionConfig.class);
        DataSource dataSource = applicationContext.getBean(DataSource.class);
        System.out.println(JSON.toJSONString(dataSource));
    }

    private static void mainFour() {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SelfConfig.class);
    }

    private static void mainThree() {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SelfConfig.class);
        annotationConfigApplicationContext.close();
    }

    private static void mainTwo() {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        annotationConfigApplicationContext.close();
    }

    private static void mainOne() {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppTestConfig.class);
        Person bean = applicationContext.getBean(Person.class);
        bean.service();
    }

}
